package Z11_3_ReentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author： pang-yun
 * @date： 2021-11-03 13:55
 * 功能目的 ：用于  可重入锁
 */
@Slf4j
public class ReentrantLockDemo {
    private static ReentrantLock reentrantLock = new ReentrantLock();

    public static void main(String[] args) {
        reentrantLock.lock();
        try {
            log.info("enter main");
            methodA();
        } finally {
            reentrantLock.unlock();
        }
    }

    public static void methodA() {
        reentrantLock.lock();
        try {
            log.info("enter m1");
            methodB();
        } finally {
            reentrantLock.unlock();
        }
    }

    public static void methodB() {
        reentrantLock.lock();
        try {
            log.info("enter m2");
        } finally {
            reentrantLock.unlock();
        }
    }


}
